package cn.edu.scujcc;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/Note")
public class NoteController {
	@Autowired
	private NoteService service;
	
	@PostMapping
	public Note createNote(@RequestBody Note c) {
		Note result = null;
		result = service.createNote(c);
		return result;
	}
	
	@PutMapping
	public Note updateNote(@RequestBody Note c) {
		Note result = null;
		result = service.updateNote(c);
		return result;
	}
	
	@GetMapping
	public List<Note> getAllNote() {
		List<Note> result = null;
		result = service.getAllNote();
		return result;
	}
	
	@GetMapping("/{leavename}")
	public Note getNote(@PathVariable User leave_name) {
		Note result = null;
		result = service.getNote(leave_name);
		return result;
	}
	
	@DeleteMapping("/{leave_name}")
	public boolean deleteNote(@PathVariable User leave_name) {
		boolean result = false;
		result = service.deleteNote(leave_name);
		return result;
	}
	
	@GetMapping("/search/{desc}")
	public Optional<Note> searchNote(@PathVariable User leave_name ){
		Optional<Note> result = null;
		result = service.searchNote(leave_name);
		return result;
	}
}
